
package com.tools.cleanmaster.common;

import android.app.IntentService;
import android.app.Notification;
import android.content.Intent;
import android.os.Build;

import com.tools.cleanmaster.CleanConstant;
import com.tools.cleanmaster.receiver.PackageChangeReceiver;

public class CommonIntentService extends IntentService {

    private static final int SERVICE_ID = 75802;

    public CommonIntentService() {
        super("CommonIntentService");
    }

    @Override
    protected void onHandleIntent(Intent intent) {
        if (intent == null) {
            return;
        }
        String action = intent.getAction();
        if (CleanConstant.ACTION_PACKAGE_CHANGE.equals(action)) {
            PackageChangeReceiver.onPackageChange(this, intent);
        }

        // Android 8.0 不支持后台开启服务
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            Notification.Builder builder = new Notification.Builder(this);
            startForeground(SERVICE_ID, builder.build());
        }
    }

}
